package cn.sdormitory.job.evaluation;

import cn.hutool.core.date.DateUtil;
import cn.sdormitory.attendance.dao.HolidayConfigDao;
import cn.sdormitory.attendance.entity.HolidayConfig;
import cn.sdormitory.evaluation.dao.WorkDayDao;
import cn.sdormitory.evaluation.entity.WorkDayEntity;
import cn.sdormitory.evaluation.service.WorkDayService;
import cn.sdormitory.evaluation.vo.WorkDayVO;
import cn.sdormitory.sys.dao.SysDictDetailDao;
import cn.sdormitory.sys.entity.SysDictDetail;
import cn.sdormitory.sys.service.SysDictDetailService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 班主任每日工作汇报任务生成
 */
@Slf4j
public class WorkDayJob extends QuartzJobBean {
    @Resource
    WorkDayDao workDayDao;

    @Resource
    HolidayConfigDao holidayConfigDao;

    @Resource
    SysDictDetailService sysDictDetailService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取节假日配置，节假日不生成工作任务
        String today = DateUtil.today();
        List<HolidayConfig> holidayByDate = holidayConfigDao.getHolidayByDate(today);
        if(holidayByDate!=null && holidayByDate.size()>0){
            log.info("{} 是假期，不生成任务",today);
            return;
        }

        List<SysDictDetail> workTypeList = sysDictDetailService.selectDictDataByType("work_type");
        //通过学生表去查询到有多少班级，班级信息，班主任信息
        List<WorkDayVO> workDayVOs = workDayDao.selectClassInfo();
        for (WorkDayVO workDayVO : workDayVOs) {
            WorkDayEntity workDayEntity = new WorkDayEntity();
            BeanUtils.copyProperties(workDayVO,workDayEntity);
            workDayEntity.setRecitePassRatio("0");
            workDayEntity.setWorkCheckRatio("0");
            workDayEntity.setCreateBy("SYSTEM");
            workDayEntity.setCreatedTime(new Date());
            workDayEntity.setTaskDate(today);
            workDayEntity.setClassId(workDayVO.getId());
            workDayDao.insert(workDayEntity);
//            //添加学生背诵考核情况数据
//            List<SysDictDetail> workTypeList1 = workTypeList;
//            for (SysDictDetail sysDictDetail : workTypeList1) {
//                workDayDao.addCheckStudent(workDayVO.getId(),workDayEntity.getId(),"1",sysDictDetail.getDictValue());
//            }
//            //添加学生作业检查情况
//            workDayDao.addCheckStudent(workDayVO.getId(),workDayEntity.getId(),"2","");
        }

    }
}
